<?php

class AcctSetTable extends Doctrine_Table
{
    public function getCurrentSet()
    {
        /*$q = Doctrine_Query::create()->from('AcctSet')
                ->where('AcctSet.id = ?', sfConfig::get("app_current_set_id"));*/
        $q = $this->addActiveSetQuery()
                //->addWhere('AcctSet.id = ?', sfConfig::get("app_current_set_id"));
                ->addWhere('AcctSet.id = ?', sfContext::getInstance()->getUser()->getAttribute("acct_set"));

        $current_set = $q->fetchOne();

        return $current_set;
    }


    public function getAllActiveSets()
    {
        /*$q = Doctrine_Query::create()->from("AcctSet")
                ->orderBy("id DESC");*/
        $q = $this->addActiveSetQuery()
                ->orderBy("id DESC");
        return $q->execute();
    }

    public function addActiveSetQuery(Doctrine_Query $q = null) {

        if(is_null($q))
        {
            //$q = Doctrine_Query::create()->from("AcctSet");
            $q = $this->createQuery();
        }

        $q->andWhere("is_activated = ?", '1');
        
        return $q;
    }
}
